package com.esri.android.map.popup;

import android.content.Context;
import android.database.DataSetObserver;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.core.internal.view.SupportMenu;
import androidx.recyclerview.widget.ItemTouchHelper;
import com.esri.android.map.ags.ArcGISPopupInfo;
import com.esri.android.map.popup.ArcGISPopupStyle;
import com.esri.core.internal.tasks.e;
import com.esri.core.map.popup.PopupChartMediaValue;
import com.esri.core.map.popup.PopupFieldInfo;
import com.esri.core.map.popup.PopupImageMediaValue;
import com.esri.core.map.popup.PopupMediaInfo;
import com.github.mikephil.charting.utils.Utils;
import com.tencent.smtt.sdk.TbsListener;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.Map;
import java.util.Set;
import org.achartengine.internal.chart.BarChart;
import org.achartengine.internal.chart.PointStyle;
import org.achartengine.internal.chart.f;
import org.achartengine.internal.model.g;
import org.achartengine.internal.model.h;
import org.achartengine.internal.renderer.XYMultipleSeriesRenderer;

/* loaded from: classes.dex */
public class ArcGISMediaAdapter implements ListAdapter {
    private static final int c = 1;
    Popup a;
    ArcGISValueFormat b;
    private Context d;
    private int e;
    private int f;
    protected ArrayList<PopupMediaInfo> mMediaInfos = new ArrayList<>();
    protected ArrayList<MediaView> mMediaViewCache;

    /* loaded from: classes.dex */
    interface MediaAdapterListener {
        void onNoMediaToDisplay();
    }

    @Override // android.widget.ListAdapter
    public boolean areAllItemsEnabled() {
        return true;
    }

    @Override // android.widget.Adapter
    public long getItemId(int i) {
        return i;
    }

    @Override // android.widget.Adapter
    public int getItemViewType(int i) {
        return 0;
    }

    @Override // android.widget.Adapter
    public int getViewTypeCount() {
        return 1;
    }

    @Override // android.widget.Adapter
    public boolean hasStableIds() {
        return true;
    }

    @Override // android.widget.ListAdapter
    public boolean isEnabled(int i) {
        return true;
    }

    @Override // android.widget.Adapter
    public void registerDataSetObserver(DataSetObserver dataSetObserver) {
    }

    @Override // android.widget.Adapter
    public void unregisterDataSetObserver(DataSetObserver dataSetObserver) {
    }

    @Override // android.widget.Adapter
    public int getCount() {
        ArrayList<PopupMediaInfo> arrayList = this.mMediaInfos;
        if (arrayList == null) {
            return 0;
        }
        return arrayList.size();
    }

    @Override // android.widget.Adapter
    public PopupMediaInfo getItem(int i) {
        ArrayList<PopupMediaInfo> arrayList = this.mMediaInfos;
        if (arrayList == null) {
            return null;
        }
        return arrayList.get(i);
    }

    public ArcGISMediaAdapter(Context context, Popup popup) {
        PopupMediaInfo[] mediaInfos;
        this.e = TbsListener.ErrorCode.ERROR_CODE_LOAD_BASE;
        this.f = 1;
        this.a = popup;
        this.b = new ArcGISValueFormat(popup);
        if (this.a.a != null && (popup.a instanceof ArcGISPopupInfo) && (mediaInfos = ((ArcGISPopupInfo) popup.a).getMediaInfos()) != null) {
            for (PopupMediaInfo popupMediaInfo : mediaInfos) {
                if (popupMediaInfo.getValue() instanceof PopupImageMediaValue) {
                    String formatValue = this.b.formatValue(this.a.mFeatureType, ((PopupImageMediaValue) popupMediaInfo.getValue()).getSourceURL(), null);
                    if (formatValue != null && formatValue.length() > 0) {
                        this.mMediaInfos.add(popupMediaInfo);
                    }
                } else {
                    this.mMediaInfos.add(popupMediaInfo);
                }
            }
            this.mMediaViewCache = new ArrayList<>(this.mMediaInfos.size());
        }
        this.d = context;
        this.e = PopupUtil.convertDpInPixels(context, this.e);
        this.f = PopupUtil.convertDpInPixels(context, this.f);
    }

    @Override // android.widget.Adapter
    public View getView(int i, View view, ViewGroup viewGroup) {
        RelativeLayout relativeLayout;
        PopupMediaInfo popupMediaInfo = this.mMediaInfos.get(i);
        if (popupMediaInfo == null) {
            return null;
        }
        if (view != null) {
            relativeLayout = (RelativeLayout) view;
            MediaView mediaView = (MediaView) relativeLayout.findViewById(1);
            int i2 = this.e;
            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(i2, i2);
            layoutParams.addRule(13, -1);
            mediaView.setLayoutParams(layoutParams);
            TextView textView = (TextView) relativeLayout.findViewById(2);
            int i3 = this.e;
            RelativeLayout.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(i3, i3 / 5);
            layoutParams2.addRule(14, 1);
            layoutParams2.addRule(8, 1);
            textView.setLayoutParams(layoutParams2);
            if (!popupMediaInfo.equals(mediaView.e())) {
                mediaView.a(popupMediaInfo);
                mediaView.a();
                textView.setText(this.b.formatValue(this.a.mFeatureType, popupMediaInfo.getTitle(), null));
            }
        } else {
            relativeLayout = new RelativeLayout(this.d);
            MediaView mediaView2 = new MediaView(this.d, this.a, popupMediaInfo);
            mediaView2.setId(1);
            mediaView2.a();
            if (i >= this.mMediaViewCache.size() || this.mMediaViewCache.get(i) == null) {
                for (int size = this.mMediaViewCache.size(); size <= i; size++) {
                    this.mMediaViewCache.add(null);
                }
                this.mMediaViewCache.add(i, mediaView2);
            }
            int i4 = this.e;
            RelativeLayout.LayoutParams layoutParams3 = new RelativeLayout.LayoutParams(i4, i4);
            layoutParams3.addRule(13, -1);
            mediaView2.setLayoutParams(layoutParams3);
            relativeLayout.addView(mediaView2);
            String formatValue = this.b.formatValue(this.a.mFeatureType, popupMediaInfo.getTitle(), null);
            TextView textView2 = new TextView(this.d);
            textView2.setId(2);
            textView2.setSingleLine();
            textView2.setText(formatValue);
            textView2.setEllipsize(TextUtils.TruncateAt.END);
            textView2.setTextColor(-1);
            textView2.setGravity(19);
            textView2.setBackgroundColor(Color.argb(180, 100, 100, 100));
            int i5 = this.e;
            RelativeLayout.LayoutParams layoutParams4 = new RelativeLayout.LayoutParams(i5, i5 / 5);
            layoutParams4.addRule(14, 1);
            layoutParams4.addRule(8, 1);
            textView2.setLayoutParams(layoutParams4);
            relativeLayout.addView(textView2);
        }
        int i6 = this.e;
        relativeLayout.setLayoutParams(new AbsListView.LayoutParams(i6, i6));
        return relativeLayout;
    }

    public int getColumnWidth() {
        return this.e;
    }

    public void setColumnWidth(int i) {
        this.e = i;
    }

    @Override // android.widget.Adapter
    public boolean isEmpty() {
        return getCount() == 0;
    }

    /* loaded from: classes.dex */
    static class MediaView extends RelativeLayout {
        protected static final int a = 0;
        protected static final int b = 1;
        protected static final int c = 2;
        protected static final int d = 3;
        ImageView e;
        PopupMediaInfo f;
        Popup g;
        ArcGISValueFormat h;
        Bitmap i;
        String j;
        STATUS k;
        protected LoadStatusListener l;
        final Handler m;
        private ArcGISPopupStyle n;
        private org.achartengine.internal.chart.a o;

        /* JADX INFO: Access modifiers changed from: protected */
        /* loaded from: classes.dex */
        public interface LoadStatusListener {
            void onLoadStatusChanged(STATUS status);
        }

        /* JADX INFO: Access modifiers changed from: protected */
        /* loaded from: classes.dex */
        public enum STATUS {
            NOT_LOADED,
            LOADING,
            LOADED
        }

        /* JADX INFO: Access modifiers changed from: private */
        /* loaded from: classes.dex */
        public class a extends Exception {
            private static final long serialVersionUID = 1;

            public a(String str) {
                super(str);
            }
        }

        public MediaView(Context context, Popup popup, PopupMediaInfo popupMediaInfo) {
            super(context);
            this.k = STATUS.NOT_LOADED;
            this.m = new Handler(new Handler.Callback() { // from class: com.esri.android.map.popup.ArcGISMediaAdapter.MediaView.1
                /* JADX WARN: Code restructure failed: missing block: B:8:0x000e, code lost:
                    if (r0 != 3) goto L8;
                 */
                /* JADX WARN: Removed duplicated region for block: B:15:0x0069  */
                @Override // android.os.Handler.Callback
                /*
                    Code decompiled incorrectly, please refer to instructions dump.
                    To view partially-correct code enable 'Show inconsistent code' option in preferences
                */
                public boolean handleMessage(android.os.Message r6) {
                    /*
                        Method dump skipped, instructions count: 242
                        To view this dump change 'Code comments level' option to 'DEBUG'
                    */
                    throw new UnsupportedOperationException("Method not decompiled: com.esri.android.map.popup.ArcGISMediaAdapter.MediaView.AnonymousClass1.handleMessage(android.os.Message):boolean");
                }
            });
            this.f = popupMediaInfo;
            this.g = popup;
            this.h = new ArcGISValueFormat(popup);
            this.n = (ArcGISPopupStyle) this.g.getLayout().getStyle();
            setBackgroundColor(Color.argb(255, (int) ItemTouchHelper.Callback.DEFAULT_SWIPE_ANIMATION_DURATION, (int) ItemTouchHelper.Callback.DEFAULT_SWIPE_ANIMATION_DURATION, (int) ItemTouchHelper.Callback.DEFAULT_SWIPE_ANIMATION_DURATION));
            ProgressBar progressBar = new ProgressBar(getContext());
            ImageView imageView = new ImageView(getContext());
            this.e = imageView;
            imageView.setPadding(4, 4, 4, 4);
            Drawable indeterminateDrawable = progressBar.getIndeterminateDrawable();
            if (indeterminateDrawable instanceof Animatable) {
                ((Animatable) indeterminateDrawable).start();
                indeterminateDrawable.setCallback(this.e);
            }
            this.e.setImageDrawable(indeterminateDrawable);
            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-2, -2);
            layoutParams.addRule(13, -1);
            addView(this.e, layoutParams);
        }

        public void a() {
            STATUS status = STATUS.LOADING;
            this.k = status;
            LoadStatusListener loadStatusListener = this.l;
            if (loadStatusListener != null) {
                loadStatusListener.onLoadStatusChanged(status);
            }
            e.a().submit(new Runnable() { // from class: com.esri.android.map.popup.ArcGISMediaAdapter.MediaView.2
                @Override // java.lang.Runnable
                public void run() {
                    try {
                        int i = AnonymousClass1.a[MediaView.this.f.getType().ordinal()];
                        if (i == 1) {
                            MediaView mediaView = MediaView.this;
                            mediaView.o = new b(mediaView, mediaView.n, true);
                            MediaView mediaView2 = MediaView.this;
                            mediaView2.i = mediaView2.a(mediaView2.o);
                        } else if (i == 2) {
                            MediaView mediaView3 = MediaView.this;
                            mediaView3.o = new b(mediaView3, mediaView3.n, false);
                            MediaView mediaView4 = MediaView.this;
                            mediaView4.i = mediaView4.a(mediaView4.o);
                        } else if (i == 3) {
                            MediaView mediaView5 = MediaView.this;
                            mediaView5.o = new c(mediaView5.n);
                            MediaView mediaView6 = MediaView.this;
                            mediaView6.i = mediaView6.a(mediaView6.o);
                        } else if (i == 4) {
                            MediaView mediaView7 = MediaView.this;
                            mediaView7.o = new d(mediaView7.n);
                            MediaView mediaView8 = MediaView.this;
                            mediaView8.i = mediaView8.a(mediaView8.o);
                        } else if (i == 5) {
                            String formatValue = MediaView.this.h.formatValue(MediaView.this.g.mFeatureType, ((PopupImageMediaValue) MediaView.this.f.getValue()).getSourceURL(), null);
                            if (formatValue != null && formatValue != "") {
                                MediaView mediaView9 = MediaView.this;
                                mediaView9.i = mediaView9.a(formatValue);
                            }
                            MediaView.this.a("No URL provided", 3);
                            return;
                        }
                        Message obtainMessage = MediaView.this.m.obtainMessage(0);
                        Bundle bundle = new Bundle();
                        bundle.putParcelable("bitmap", MediaView.this.i);
                        obtainMessage.obj = bundle;
                        obtainMessage.sendToTarget();
                    } catch (a e) {
                        MediaView.this.a(e.getMessage(), 1);
                    } catch (OutOfMemoryError unused) {
                        MediaView.this.a("Ran out of memory when retrieving this media", 2);
                    }
                }
            });
        }

        public Bitmap b() {
            return this.i;
        }

        public org.achartengine.internal.chart.a c() {
            return this.o;
        }

        public String d() {
            return this.j;
        }

        PopupMediaInfo e() {
            return this.f;
        }

        void a(PopupMediaInfo popupMediaInfo) {
            this.f = popupMediaInfo;
        }

        void a(String str, int i) {
            Message obtainMessage = this.m.obtainMessage(i);
            obtainMessage.obj = str;
            obtainMessage.sendToTarget();
        }

        private Bitmap a(byte[] bArr) {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inInputShareable = true;
            options.inPurgeable = true;
            return BitmapFactory.decodeByteArray(bArr, 0, bArr.length, options);
        }

        Bitmap a(String str) throws a {
            if (str == null) {
                return null;
            }
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            try {
                try {
                    try {
                        Bitmap a2 = a(com.esri.core.internal.io.handler.a.a(str, (Map<String, String>) null));
                        try {
                            byteArrayOutputStream.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        return a2;
                    } catch (MalformedURLException unused) {
                        throw new a("Cannot load image due to an invalid url");
                    } catch (IOException unused2) {
                        throw new a("Cannot load image");
                    }
                } catch (Exception e2) {
                    e2.printStackTrace();
                    throw new a("Cannot load image");
                } catch (OutOfMemoryError unused3) {
                    throw new a("cannot load image due to low memory");
                }
            } catch (Throwable th) {
                try {
                    byteArrayOutputStream.close();
                } catch (IOException e3) {
                    e3.printStackTrace();
                }
                throw th;
            }
        }

        Bitmap a(org.achartengine.internal.chart.a aVar) {
            Bitmap createBitmap = Bitmap.createBitmap(512, 512, Bitmap.Config.ARGB_8888);
            aVar.a(new Canvas(createBitmap), 0, 0, 512, 512, new Paint());
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            byte[] byteArray = createBitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream) ? byteArrayOutputStream.toByteArray() : null;
            try {
                byteArrayOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            Bitmap a2 = a(byteArray);
            createBitmap.recycle();
            return a2;
        }

        /* loaded from: classes.dex */
        private class c extends f implements ArcGISPopupStyle.IPopupStylable {
            private static final long serialVersionUID = 1;
            XYMultipleSeriesRenderer a;

            c(ArcGISPopupStyle arcGISPopupStyle) {
                super(new g(), new XYMultipleSeriesRenderer());
                PopupChartMediaValue popupChartMediaValue = (PopupChartMediaValue) MediaView.this.f.getValue();
                XYMultipleSeriesRenderer e = e();
                this.a = e;
                e.f(false);
                this.a.j(5.0f);
                this.a.a(MediaView.this.f());
                this.a.a(Paint.Align.RIGHT);
                this.a.b(Paint.Align.RIGHT);
                applyStyle(arcGISPopupStyle, ArcGISPopupStyle.STYLE_ELEMENT.MEDIA_VALUES);
                arcGISPopupStyle.registerStylable(this);
                int[] iArr = {SupportMenu.CATEGORY_MASK};
                PointStyle[] pointStyleArr = {PointStyle.DIAMOND};
                for (int i = 0; i < 1; i++) {
                    org.achartengine.internal.renderer.c cVar = new org.achartengine.internal.renderer.c();
                    cVar.b(true);
                    cVar.b(iArr[i]);
                    cVar.a(pointStyleArr[i]);
                    this.a.a(cVar);
                }
                g f = f();
                h hVar = new h(MediaView.this.f.getTitle());
                String[] fields = popupChartMediaValue.getFields();
                int length = fields.length;
                double[] dArr = new double[length];
                double[] dArr2 = new double[fields.length];
                int i2 = 0;
                while (i2 < fields.length) {
                    int i3 = i2 + 1;
                    dArr[i2] = i3;
                    Object attributeValue = MediaView.this.g.b.getAttributeValue(fields[i2]);
                    dArr2[i2] = attributeValue == null ? Utils.DOUBLE_EPSILON : new BigDecimal(attributeValue.toString()).setScale(1, RoundingMode.HALF_UP).doubleValue();
                    i2 = i3;
                }
                double d = Double.MIN_VALUE;
                int i4 = 0;
                double d2 = Utils.DOUBLE_EPSILON;
                while (i4 < length) {
                    d = dArr2[i4] > d ? dArr2[i4] : d;
                    if (dArr2[i4] < d2) {
                        d2 = dArr2[i4];
                    }
                    hVar.a(dArr[i4], dArr2[i4]);
                    i4++;
                    popupChartMediaValue = popupChartMediaValue;
                    d = d;
                }
                f.a(hVar);
                String[] fields2 = popupChartMediaValue.getFields();
                int length2 = fields2.length;
                double d3 = 1.0d;
                int i5 = 0;
                while (i5 < length2) {
                    String str = fields2[i5];
                    PopupFieldInfo fieldInfo = MediaView.this.g.a == null ? null : MediaView.this.g.a.getFieldInfo(str);
                    if (fieldInfo != null && fieldInfo.getLabel() != null) {
                        str = fieldInfo.getLabel();
                    }
                    this.a.a(d3, str);
                    i5++;
                    d3 += 1.0d;
                }
                this.a.a(0.5d);
                XYMultipleSeriesRenderer xYMultipleSeriesRenderer = this.a;
                double d4 = length;
                Double.isNaN(d4);
                xYMultipleSeriesRenderer.b(d4 + 0.5d);
                this.a.c(d2);
                this.a.d(d + 1.0d);
                this.a.f(0);
                this.a.g(length + 1);
            }

            @Override // com.esri.android.map.popup.ArcGISPopupStyle.IPopupStylable
            public Set<ArcGISPopupStyle.STYLE_ELEMENT> getRegisteredStyle() {
                return EnumSet.of(ArcGISPopupStyle.STYLE_ELEMENT.MEDIA_VALUES);
            }

            @Override // com.esri.android.map.popup.ArcGISPopupStyle.IPopupStylable
            public void applyStyle(ArcGISPopupStyle arcGISPopupStyle, ArcGISPopupStyle.STYLE_ELEMENT style_element) {
                this.a.a(arcGISPopupStyle.getMediaChartValuesFontSize());
                this.a.e(arcGISPopupStyle.getMediaChartValuesFontSize());
                this.a.a(arcGISPopupStyle.getMediaChartValuesFontType(), arcGISPopupStyle.getMediaChartValuesFontStyle());
                this.a.c(arcGISPopupStyle.getMediaChartValuesColor());
                this.a.d(arcGISPopupStyle.getMediaChartValuesColor());
            }
        }

        /* loaded from: classes.dex */
        private class d extends org.achartengine.internal.chart.g implements ArcGISPopupStyle.IPopupStylable {
            private static final long serialVersionUID = 1;
            private org.achartengine.internal.renderer.a b;
            private int c;

            public d(ArcGISPopupStyle arcGISPopupStyle) throws a {
                super(new org.achartengine.internal.model.a(MediaView.this.f.getTitle()), new org.achartengine.internal.renderer.a());
                String[] fields;
                PopupChartMediaValue popupChartMediaValue = (PopupChartMediaValue) MediaView.this.f.getValue();
                boolean z = false;
                this.c = popupChartMediaValue.getFields() == null ? 0 : popupChartMediaValue.getFields().length;
                this.b = b();
                applyStyle(arcGISPopupStyle, ArcGISPopupStyle.STYLE_ELEMENT.MEDIA_VALUES);
                arcGISPopupStyle.registerStylable(this);
                this.b.a(MediaView.this.f());
                this.b.f(false);
                org.achartengine.internal.model.a a = a();
                if (this.c > 0) {
                    for (String str : popupChartMediaValue.getFields()) {
                        PopupFieldInfo fieldInfo = MediaView.this.g.a == null ? null : MediaView.this.g.a.getFieldInfo(str);
                        String label = (fieldInfo == null || fieldInfo.getLabel() == null) ? str : fieldInfo.getLabel();
                        Object attributeValue = MediaView.this.g.b.getAttributeValue(str);
                        double parseDouble = attributeValue == null ? 0.0d : Double.parseDouble(attributeValue.toString());
                        if (parseDouble < Utils.DOUBLE_EPSILON) {
                            throw new a("Invalid chart");
                        }
                        a.a(label, parseDouble);
                    }
                }
                int i = 0;
                while (true) {
                    if (i >= a.c()) {
                        break;
                    } else if (a.b(i) > Utils.DOUBLE_EPSILON) {
                        z = true;
                        break;
                    } else {
                        i++;
                    }
                }
                if (!z) {
                    throw new a("No values");
                }
            }

            @Override // com.esri.android.map.popup.ArcGISPopupStyle.IPopupStylable
            public Set<ArcGISPopupStyle.STYLE_ELEMENT> getRegisteredStyle() {
                return EnumSet.of(ArcGISPopupStyle.STYLE_ELEMENT.MEDIA_VALUES);
            }

            @Override // com.esri.android.map.popup.ArcGISPopupStyle.IPopupStylable
            public void applyStyle(ArcGISPopupStyle arcGISPopupStyle, ArcGISPopupStyle.STYLE_ELEMENT style_element) {
                this.b.a(arcGISPopupStyle.getMediaChartValuesFontSize());
                this.b.a(arcGISPopupStyle.getMediaChartValuesFontType(), arcGISPopupStyle.getMediaChartValuesFontStyle());
                this.b.d(arcGISPopupStyle.getMediaChartValuesColor());
                for (int i = 0; i < this.b.a(); i++) {
                    org.achartengine.internal.renderer.a aVar = this.b;
                    aVar.b(aVar.a(i));
                }
                for (int i2 = 0; i2 < this.c; i2++) {
                    int[] colorRamp = arcGISPopupStyle.getColorRamp(i2);
                    org.achartengine.internal.renderer.b bVar = new org.achartengine.internal.renderer.b();
                    bVar.b(colorRamp[0]);
                    bVar.a(colorRamp[1]);
                    this.b.a(bVar);
                }
            }
        }

        /* loaded from: classes.dex */
        private class b extends BarChart implements ArcGISPopupStyle.IPopupStylable {
            private static final long serialVersionUID = 1;
            final /* synthetic */ MediaView a;
            private XYMultipleSeriesRenderer h;
            private int i;

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            public b(MediaView mediaView, ArcGISPopupStyle arcGISPopupStyle, boolean z) {
                super(new g(), new XYMultipleSeriesRenderer(), BarChart.Type.DEFAULT);
                double d;
                g gVar;
                double doubleValue;
                MediaView mediaView2 = mediaView;
                this.a = mediaView2;
                PopupChartMediaValue popupChartMediaValue = (PopupChartMediaValue) mediaView2.f.getValue();
                this.i = popupChartMediaValue.getFields() == null ? 0 : popupChartMediaValue.getFields().length;
                this.h = e();
                applyStyle(arcGISPopupStyle, ArcGISPopupStyle.STYLE_ELEMENT.MEDIA_VALUES);
                arcGISPopupStyle.registerStylable(this);
                this.h.a(z ? XYMultipleSeriesRenderer.Orientation.HORIZONTAL : XYMultipleSeriesRenderer.Orientation.VERTICAL);
                this.h.i(false);
                this.h.f(false);
                this.h.a(mediaView.f());
                this.h.e(0.2d);
                this.h.a(Paint.Align.RIGHT);
                this.h.b(Paint.Align.RIGHT);
                g f = f();
                double d2 = Double.MIN_VALUE;
                if (this.i > 0) {
                    org.achartengine.internal.model.a aVar = new org.achartengine.internal.model.a(mediaView2.f.getTitle());
                    String[] fields = popupChartMediaValue.getFields();
                    int length = fields.length;
                    double d3 = 1.0d;
                    int i = 0;
                    double d4 = Utils.DOUBLE_EPSILON;
                    while (i < length) {
                        String str = fields[i];
                        PopupFieldInfo fieldInfo = mediaView2.g.a == null ? null : mediaView2.g.a.getFieldInfo(str);
                        String label = (fieldInfo == null || fieldInfo.getLabel() == null) ? str : fieldInfo.getLabel();
                        Object attributeValue = mediaView2.g.b.getAttributeValue(str);
                        if (attributeValue == null) {
                            gVar = f;
                            doubleValue = Utils.DOUBLE_EPSILON;
                        } else {
                            gVar = f;
                            doubleValue = new BigDecimal(attributeValue.toString()).setScale(1, RoundingMode.HALF_UP).doubleValue();
                        }
                        double d5 = d3 + 1.0d;
                        this.h.a(d3, label);
                        aVar.a(doubleValue);
                        d2 = doubleValue > d2 ? doubleValue : d2;
                        if (doubleValue < d4) {
                            d4 = doubleValue;
                        }
                        i++;
                        mediaView2 = mediaView;
                        f = gVar;
                        d3 = d5;
                    }
                    f.a(aVar.d());
                    d = d4;
                } else {
                    d = Utils.DOUBLE_EPSILON;
                }
                this.h.a(0.5d);
                this.h.c(d);
                this.h.d(d2);
                XYMultipleSeriesRenderer xYMultipleSeriesRenderer = this.h;
                double d6 = this.i;
                Double.isNaN(d6);
                xYMultipleSeriesRenderer.b(d6 + 0.5d);
                this.h.f(0);
                this.h.g(this.i);
            }

            @Override // com.esri.android.map.popup.ArcGISPopupStyle.IPopupStylable
            public Set<ArcGISPopupStyle.STYLE_ELEMENT> getRegisteredStyle() {
                return EnumSet.of(ArcGISPopupStyle.STYLE_ELEMENT.MEDIA_VALUES);
            }

            @Override // com.esri.android.map.popup.ArcGISPopupStyle.IPopupStylable
            public void applyStyle(ArcGISPopupStyle arcGISPopupStyle, ArcGISPopupStyle.STYLE_ELEMENT style_element) {
                this.h.a(arcGISPopupStyle.getMediaChartValuesFontSize());
                this.h.a(arcGISPopupStyle.getMediaChartValuesFontType(), arcGISPopupStyle.getMediaChartValuesFontStyle());
                this.h.c(arcGISPopupStyle.getMediaChartValuesColor());
                this.h.d(arcGISPopupStyle.getMediaChartValuesColor());
                for (int i = 0; i < this.i; i++) {
                    int[] colorRamp = arcGISPopupStyle.getColorRamp(i);
                    org.achartengine.internal.renderer.b bVar = new org.achartengine.internal.renderer.b();
                    bVar.b(colorRamp[0]);
                    bVar.a(colorRamp[1]);
                    this.h.a(bVar);
                }
            }
        }

        int[] f() {
            return new int[]{10, 20, 10, 20};
        }

        public STATUS g() {
            return this.k;
        }
    }

    /* renamed from: com.esri.android.map.popup.ArcGISMediaAdapter$1  reason: invalid class name */
    /* loaded from: classes.dex */
    static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] a;

        static {
            int[] iArr = new int[PopupMediaInfo.MEDIA_TYPE.values().length];
            a = iArr;
            try {
                iArr[PopupMediaInfo.MEDIA_TYPE.COLUMNCHART.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                a[PopupMediaInfo.MEDIA_TYPE.BARCHART.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                a[PopupMediaInfo.MEDIA_TYPE.LINECHART.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                a[PopupMediaInfo.MEDIA_TYPE.PIECHART.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                a[PopupMediaInfo.MEDIA_TYPE.IMAGE.ordinal()] = 5;
            } catch (NoSuchFieldError unused5) {
            }
        }
    }
}
